<?php
class plmorder {
	static $SOAP;
	static $method;
	public function __construct($url,$user,$pass){
		self::$SOAP=new stdClass;
		self::$SOAP->client=new SoapClient('http://'.$url.'/api/?wsdl');
		self::$SOAP->session=self::$SOAP->client->login($user,$pass);
		}
	
	public static function call($method,$args){
		return self::$SOAP->client->call(self::$SOAP->session,$method,$args);
		}
	
	public function getAllOrder(){
		$filters=array(
					   'billing_name'=>array('like'=>'%')
					   );
		$orders=$this->call('sales_order.list',array($filters));
		return $orders;
	}
	
	public function getOneOrder($id){
		$order=$this->call('sales_order.info',$id);
		return $order;
		}
	
	public function getAllProduct(){
		$filters=array(
					   'sku'=>array('like'=>'%')
					   );
		$products=$this->call('product.list',array($filters));
		return $products;
		}
		
	public function getOneProduct($id){
		$product=$this->call('product.info',$id);
		return $product;
		}
	
	public function getProductMedia($id){
		$media=$this->call('catalog_product_attribute_media.list',array('id'=>$id));
		return $media;
		}
}

//$plm=new plmorder('192.168.1.20:8004','ben','162452');
//$products=$plm->getAllProduct();
////$id=$products[0]['product_id'];
////$imagelink=$plm->getProductMedia($id);
////print_r($imagelink);
//$info=$plm->getOneProduct($products[0]['product_id']);
//print_r($info);
//$count=sizeof($products);
//for($i=0;$i<$count;$i++){
//	$id=$products[$i]['product_id'];
//	$info=$plm->getOneProduct($id);
//	$imagelink=$plm->getProductMedia($id);
//	if(sizeof($imagelink)=='0'){
//				$imagelink[0]['file']="no";
//				}
//	array_push($info,$imagelink[0]['file']);
//	$products[$i]['set']=$info;
//	}
//$file=dirname(__FILE__)."/temp.xml";
//file_put_contents($file,serialize($products));
//$media=$plm->getProductMedia($products[0]['product_id']);
//print_r($media);
?>